home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / OvalShp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.4 KB  |  259 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                OvalShp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef OVALSHP_H
  23. #include "OvalShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. // ----- Foundation Includes -----
  107.  
  108. #ifndef FWSTREAM_H
  109. #include "FWStream.h"
  110. #endif
  111.  
  112. // ----- OpenDoc Includes -----
  113.  
  114. #ifndef SOM_ODTransform_xh
  115. #include <Trnsform.xh>
  116. #endif
  117.  
  118. //========================================================================================
  119. // Runtime Information
  120. //========================================================================================
  121.  
  122. #ifdef FW_BUILD_MAC
  123. #pragma segment odfdrawshapes
  124. #endif
  125.  
  126. //========================================================================================
  127. // RunTime Info
  128. //========================================================================================
  129.  
  130. FW_DEFINE_CLASS_M1(COvalShape, CBoundedShape)
  131.  
  132. FW_REGISTER_ARCHIVABLE_CLASS(LOvalShape, COvalShape, COvalShape::Read, CBaseShape::Write)
  133.  
  134. //========================================================================================
  135. // class COvalShape
  136. //========================================================================================
  137.  
  138. //----------------------------------------------------------------------------------------
  139. // COvalShape::COvalShape
  140. //----------------------------------------------------------------------------------------
  141.  
  142. COvalShape::COvalShape():
  143.     CBoundedShape(kOvalShape, kFrameOnly)
  144. {
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. // COvalShape::COvalShape
  149. //----------------------------------------------------------------------------------------
  150.  
  151. COvalShape::COvalShape(FW_CReadableStream& archive) :
  152.     CBoundedShape(archive)
  153. {    
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // COvalShape::~COvalShape
  158. //----------------------------------------------------------------------------------------
  159.  
  160. COvalShape::~COvalShape()
  161. {
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. // COvalShape::OutlineShape
  166. //----------------------------------------------------------------------------------------
  167.  
  168. void COvalShape::OutlineShape(FW_CGraphicContext& gc, const FW_PInk& ink, const FW_PStyle& style, const FW_CRect& rect)
  169. {
  170.     FW_CRect bounds(rect);
  171.     AdjustRectForPenSize(bounds, style->GetPenSize());
  172.     FW_COvalShape::RenderOval(gc,
  173.                               bounds,
  174.                               FW_kFrame,
  175.                               ink, style);
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. // COvalShape::RenderShape
  180. //----------------------------------------------------------------------------------------
  181.  
  182. void COvalShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  183. {
  184.     FW_CRect rect(fRect);
  185.     AdjustRectForPenSize(rect, GetPenSize());
  186.     
  187.     if (HasFillStyle())
  188.         FW_COvalShape::RenderOval(gc, rect, FW_kFill, fFillInk, fFillStyle);
  189.     
  190.     if (HasFrameStyle())
  191.         FW_COvalShape::RenderOval(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. // COvalShape::HitTest
  196. //----------------------------------------------------------------------------------------
  197.  
  198. FW_Boolean COvalShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  199. {    
  200.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  201.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  202.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  203.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  204.  
  205.     FW_CRect bounds(fRect);
  206.     AdjustRectForPenSize(bounds, GetPenSize());
  207.  
  208.     FW_COvalShape ovalShape(bounds, HasFillStyle() ? FW_kFill : FW_kFrame);
  209.     return ovalShape.HitTest(gc, mouse, FW_IntToFixed(2));
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // COvalShape::GetClipRegion
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void COvalShape::GetClipRegion(Environment* ev, ODShape* clipRegion)
  217. {
  218.     FW_CRect bounds(fRect);
  219.     AdjustRectForPenSize(bounds, GetPenSize());
  220.     
  221.     ODShape* ovalShape = ::FW_CreateOvalODShape(ev, bounds);
  222.     clipRegion->CopyFrom(ev, ovalShape);
  223.     ovalShape->Release(ev);
  224.     
  225.     if (FrameOnly())
  226.     {
  227.         bounds.Inset(GetPenSize(), GetPenSize());
  228.         ovalShape = ::FW_CreateOvalODShape(ev, bounds);
  229.         clipRegion->Subtract(ev, ovalShape);
  230.         ovalShape->Release(ev);
  231.     }
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // COvalShape::CreateShapeOutline
  236. //----------------------------------------------------------------------------------------
  237.  
  238. ODShape* COvalShape::CreateShapeOutline(Environment *ev)
  239. {
  240.     FW_CRect bounds(fRect);
  241.     AdjustRectForPenSize(bounds, GetPenSize());
  242.     
  243.     ODShape *dragRgn = ::FW_CreateOvalODShape(ev, bounds);        // We don't acquire it because we return it
  244.     
  245.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  246.     
  247.     return dragRgn;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. // COvalShape::Read
  252. //----------------------------------------------------------------------------------------
  253.  
  254. void* COvalShape::Read(FW_CReadableStream& archive)
  255. {
  256.     return new COvalShape(archive);
  257. }
  258.  
  259.